package com.zpself.module.算法练习.算法.排序算法;

import org.junit.Test;

/**
 * @author By ZengPeng
 * @Description 冒泡:从arr[0],一直比上去,大的往上冒:->第一轮 arr[length-1]就是最大的了
 * @date in  2021/4/7 19:53
 * @Modified By
 */
public class 冒泡算法_O_n2 {
    @Test
    public void main(){
        int[] number = new int[]{12,5,6,4,7,8,5,101,0,72};
        for (int i : maoPao(number)) {
            System.out.print(i+",");
        }
    }
    private int[] maoPao(int[] num) {
        for (int i = 0; i < num.length; i++) {
            for (int j = 0; j < num.length-i-1; j++) {
                if(num[j]>num[j+1]){
                    num[j]= num[j]^num[j+1];
                    num[j+1]= num[j]^num[j+1];
                    num[j]= num[j]^num[j+1];
                }
            }
        }
        return num;
    }
}
